package com.jcloud.codetest1.component;

import com.jcloud.codetest1.domain.RecordItem;
import org.springframework.stereotype.Component;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * @author
 * @date 2021-04-18 11:28
 */
@Component
public class RecordItemBlockingQueue {
    public static final  int QUEUE_SIZE = 200;
    private BlockingQueue<RecordItem> queue;

    public RecordItemBlockingQueue() {
        queue = new LinkedBlockingQueue<RecordItem>(QUEUE_SIZE);
    }


    public void putQueue(RecordItem recordItem)  {
        try {
            queue.put(recordItem);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public boolean isContain(RecordItem recordItem){
        return queue.contains(recordItem);
    }

    public void addQueue(RecordItem recordItem)  {
        queue.add(recordItem);
    }


    public RecordItem takeQueue()  {
        RecordItem record = null;
        try {
            record = queue.take();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return record;
    }


    public BlockingQueue<RecordItem> getQueue() {
        return queue;
    }

    public int remainingCapacity(){
        return queue.remainingCapacity();
    }
}
